﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Business.Sec;
using ESOL.Common;
using ESOL.Common.Entity;

namespace ESOL.WinUI.Sec
{
    public partial class frmMaintainMenuMulit : BaseForm.frmBaseDialogyMaintainForm
    {
        #region Variable
        private DataTable mDataSource;
        #endregion

        #region Constructor
        public frmMaintainMenuMulit(DataTable dt)
        {
            InitializeComponent();
            mDataSource = dt;
        }
        #endregion

        #region Functions
        private bool SaveMenu(List<SecMenuEntity> list)
        {
            try
            {
                return SecMenuBs.UpdateMenus(list);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        #endregion

        #region Event
        protected override void OnShown(EventArgs e)
        {
            gvMain.DataSource = mDataSource;
        }
        protected override void Click_Save()
        {
            List<SecMenuEntity> list = new List<SecMenuEntity>();
            DataTable dt = gvMain.DataSource as DataTable;
            foreach(DataRow dr in dt.Rows)
            {
                if (dr.RowState == DataRowState.Modified)
                {
                    SecMenuEntity entity = new SecMenuEntity(dr);
                    list.Add(entity);
                }
            }
            if (SaveMenu(list))
            {
                DialogResult = DialogResult.OK;
            }
        }
        #endregion
    }
}
